﻿<link href="~/lib/layui/css/layui.css" rel="stylesheet" />   @* 一 ①样式 *@ @* ②layui js库 *@
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/layui/layui.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<h2>注册</h2>
@* {
  "id": 2,
  "name": "admin1",
  "level": 0,
  "pwd": "e10adc3949ba59abbe56e057f20f883e",
  "email": "138888888888@qq.com",
  "phone": "138888888888",
  "jifenVal": 100
} *@
<table class="layui-table">
    <tr>
        <td>用户名</td>
        <td><input type="type" id="name" value="" /></td>
    </tr> 
    
    <tr>
        <td>密码</td>
        <td><input type="password" id="pwd" value="" /></td>
    </tr>
    
    <tr>
        <td>确认密码</td>
        <td><input type="password" id="pwd1" value="" /></td>
    </tr>
    <tr>
        <td>邮箱</td>
        <td><input type="type" id="email" value="" /></td>
    </tr>
    <tr>
        <td>手机号</td>
        <td><input type="type" id="phone" value="" /></td>
    </tr>


    <tr>
        <td> </td>
        <td><input type="button" id="btnZhuce" class="layui-btn layui-bg-blue" value="注册" onclick="ZhuCe()" /></td>
    </tr>
</table>

        <script>

            function ZhuCe() {
                var name = $("#name").val();
                var pwd = $("#pwd").val();
                var pwd1 = $("#pwd1").val();
                var email = $("#email").val();
                var phone = $("#phone").val();

                if (!name) {
                    alert("用户名不能为空!"); return;
                }
                if (!pwd) {
                    alert("密码不能为空!"); return;
                }

                if (!email) {
                    alert("邮箱不能为空!"); return;
                }
                if (!phone) {
                    alert("手机号不能为空!"); return;
                }


                if (pwd != pwd1) {
                    alert("两次密码必须一致!"); return;
                }
                var obj = {
                    "id": 0,
                    "name": name,
                    "level": 0,
                    "pwd": pwd,
                    "email": email,
                    "phone": phone,
                    "jifenVal": 100
                }

                $.ajax({

                    url: 'https://localhost:7061/api/Member/Add',
                    type: 'post',
                    data: JSON.stringify(obj),
                     contentType: 'application/json',
                success: function (res) {
                        if (res > 0) {
                            alert("注册成功!");
                        } else {
                            alert("注册失败!");
                        }
                    }
                });

            }
        </script>